package com.ogms.dge.container.modules.data.converter;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ogms.dge.container.modules.data.entity.SourceEntity;
import com.ogms.dge.container.modules.data.vo.SourceVo;
import com.ogms.dge.container.modules.sys.service.SysUserService;
import org.mapstruct.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @name: SourceConverter
 * @description: TODO
 * @author: Lingkai Shi
 * @date: 9/23/2024 10:56 PM
 * @version: 1.0
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SourceConverter {
    @Mapping(target = "createUsername", ignore = true)
    SourceVo po2Vo(SourceEntity sourceEntity, @Context SysUserService userService);

    @AfterMapping
    default void handleCustomFields(SourceEntity sourceEntity, @MappingTarget SourceVo sourceVo, @Context SysUserService userService) {
        sourceVo.setCreateUsername(userService.getById(sourceEntity.getCreateUserId()).getUsername());
    }

    default List<SourceVo> poList2VoList(List<SourceEntity> serviceEntityList, @Context SysUserService userService) {
        return serviceEntityList.stream()
                .map(service -> po2Vo(service, userService))
                .collect(Collectors.toList());
    }
}
